"""service URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.conf.urls import url
from django.contrib import admin
from django.urls import path, include
from django.views import static
from rest_framework import permissions
from drf_yasg.views import get_schema_view
from drf_yasg import openapi
from rest_framework_jwt.views import obtain_jwt_token
# from apps.task.job import test_unzip_file
from apps.users.views import LogoutView
from apps.utils.views import download_excel
from apps.rb_data.get_data import rb_check, update_name_list, data_cheat_check
# scheduler = BackgroundScheduler()
# scheduler.add_jobstore(DjangoJobStore(), 'default')


# 时间间隔3秒钟打印一次当前的时间
# @register_job(scheduler, "interval", seconds=60 * 60 * 24, id='rb_data_check')
# def job1():
#     rb_check()
#
#
# @register_job(scheduler, 'interval', seconds=60 * 60 * 1, id='update_name_list')
# def job2():
#     update_name_list()
#
#
# @register_job(scheduler, 'interval', seconds=60 * 60 * 3, id='data_cheat_check')
# def job3():
#     data_cheat_check()


# @register_job(scheduler, 'interval', days=14, id='test_unzip_file')
# def job4():
#     test_unzip_file()


# per-execution monitoring, call register_events on your scheduler
# register_events(scheduler)
# scheduler.start()

schema_view = get_schema_view(
    openapi.Info(
        title="测试工程API",
        default_version='v1.0',
        description="测试工程接口文档",
        terms_of_service="",
        contact=openapi.Contact(email="wangfan13@lenovo.com"),
        license=openapi.License(name=""),
    ),
    public=True,
    permission_classes=(permissions.AllowAny,),
)

urlpatterns = [
    path('api/admin/', admin.site.urls),
    path('api/login/', obtain_jwt_token),
    url(r'api/logout/', LogoutView.as_view()),
    path('api/case/', include('apps.case.urls')),
    path('api/users/', include('apps.users.urls')),
    path('api/common/initial_excel', download_excel),
    path('api/dashboard/', include('apps.dashboard.urls')),
    path('api/rb_data/', include('apps.rb_data.urls')),
    url(r'api/static/(?P<path>.*)$', static.serve, {'document_root': settings.STATIC_ROOT}, name='static'),
    # 配置drf-yasg路由
    url('api/swagger(?P<format>\.json|\.yaml)$', schema_view.without_ui(cache_timeout=0), name='schema-json'),
    path('api/swagger/', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'),
    path('api/redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'),
]
